package o2o.config.jms.producer;

import com.jinyouapp.common.tools.jms.model.JMSNotify;
import o2o.config.jms.convert.NotifyMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Destination;

@Component
public class TopicMessageProducer {

    @Autowired
    private JmsTemplate jmsTemplate;
    @Autowired
    private NotifyMessageConverter messageConverter;
    @Autowired
    private Destination toppicDestination;

    private void sendMessage(JMSNotify notify) {

        jmsTemplate.setMessageConverter(messageConverter);
        jmsTemplate.setPubSubDomain(false);
        jmsTemplate.convertAndSend(toppicDestination, notify);
    }

    public NotifyMessageConverter getMessageConverter() {
        return messageConverter;
    }

    public void setMessageConverter(NotifyMessageConverter messageConverter) {
        this.messageConverter = messageConverter;
    }

    public void sendTopic(JMSNotify notify) {
        this.sendMessage(notify);
    }

}
